read project tsconfig.json when resolving compiler options - #1865
Open
joeferner wants to merge 1 commit into
Open
read project tsconfig.json when resolving compiler options#1865joeferner wants to merge 1 commit into
joeferner wants to merge 1 commit into
Conversation
validateCompilerOptions now uses TypeScript's own API (findConfigFile, readConfigFile, parseJsonConfigFileContent) to read the project's tsconfig.json and merge its compiler options with any tsoa-level compilerOptions overrides. This ensures moduleResolution, paths, customConditions, and other settings are honoured when TSOA creates its TypeScript program — fixing cross-package z.infer<> expansion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #1864
All Submissions:
If this is a new feature submission:
Potential Problems With The Approach
validateCompilerOptionspreviously acceptedconfig?: Record<string, unknown>and returned it cast asCompilerOptions. The new behaviour readstsconfig.jsonfrom the current working directory upward, so callers that pass an explicitcwdargument can now control which tsconfig is discovered. Callers that pass neitherconfignorcwdwill pick up whatevertsconfig.jsonTypeScript finds viats.findConfigFile— this is the correct default, but if a project has an unusual tsconfig location the discovery path may differ from what was previously assumed (previously: nothing was read at all, so any change here is strictly an improvement).The
compilerOptionsfield intsoa.jsoncontinues to work as before — values there are merged on top of the tsconfig-derived options, so explicit overrides take full precedence.Test plan
New unit tests in
tests/unit/swagger/validateCompilerOptions.spec.tscover:moduleResolution: bundlerandcustomConditions: ["source"]are read from the fixture tsconfig and returned as the correct numeric TypeScript enum values.cwdis/(filesystem root, which has no tsconfig), the returned options have nomoduleResolutionorcustomConditionsset; the function does not throw.tsoa.json'scompilerOptionsblock override the tsconfig-derived values; options not overridden (e.g.moduleResolution) are still present from the tsconfig.{ moduleResolution: "node16" }as an override producests.ModuleResolutionKind.Node16(the numeric value), confirming thatts.convertCompilerOptionsFromJsonis applied correctly.Widgetfrom a package resolved viapathsin tsconfig correctly expands to its full property set (id,name,active). Without the fix this throws becausepathsis never read.z.infer<>— a controller importingZodWidget = z.infer<typeof ZodWidgetSchema>from the same cross-package source correctly expands to its full property set (id,label,enabled). Without the fix this throws for the same reason; even if it didn't, reading from a compiled.d.tswould collapse the type to{}.